<template>
  <el-container style="height: 600px; border: 1px solid #eee">
    <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
      <el-menu :default-openeds="['1', '3']">
        <el-submenu index="1">
          <template slot="title"
            ><i class="el-icon-office-building"></i>资料信息</template
          >

          <el-menu-item index="1-4-1"
            ><router-link to="/emp"
              ><el-link type="primary" :underline="false" icon="el-icon-user"
                >员工信息</el-link
              ></router-link
            ></el-menu-item
          >
          <el-menu-item index="1-4-2">
            <router-link to="/dept"
              ><el-link type="primary" :underline="false" icon="el-icon-wallet"
                >部门信息</el-link
              ></router-link
            ></el-menu-item
          >
          <el-menu-item index="1-4-3">
            <router-link to="/user">
              <el-link
                type="primary"
                :underline="false"
                icon="el-icon-user-solid"
                >用户信息</el-link
              >
            </router-link></el-menu-item
          >
          <el-menu-item index="1-4-4">
            <router-link to="/role">
              <el-link type="primary" :underline="false" icon="el-icon-s-custom"
                >角色管理</el-link
              >
            </router-link></el-menu-item
          >
          <el-menu-item index="1-4-5">
            <router-link to="/menu">
              <el-link type="primary" :underline="false" icon="el-icon-s-order"
                >菜单管理</el-link
              >
            </router-link></el-menu-item
          >
          <el-menu-item index="1-4-6">
            <router-link to="/power">
              <el-link
                type="primary"
                :underline="false"
                icon="el-icon-wind-power"
                >权限设置(废弃)</el-link
              >
            </router-link></el-menu-item
          >
        </el-submenu>
      </el-menu>
    </el-aside>

    <el-container>
      <el-header style="text-align: right; font-size: 12px">
        <el-dropdown>
          <i class="el-icon-setting" style="margin-right: 15px"></i>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item icon="el-icon-cloudy" @click.native="exit"
              >注销</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
        <span v-text="username"></span>
      </el-header>

      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  data() {
    return {
      username: "",
    };
  },
  methods: {
    //注销的方法
    exit() {
      //清除浏览器上的token并且将发送请求到后台

      this.http({
        url: "/exit",
        method: "get",
      }).then(({ data }) => {
        if (data.code == 1) {
          this.$message({
            message: data.msg,

            type: "success",
          });
          localStorage.removeItem("token");
          this.$router.push("/login");
        }
      });
    },
    getName() {
      this.http({
        url: "/tokeParse",
        method: "get",
      }).then(({ data }) => {
        if (data.code == 1) {
          this.username = data.data.username;
        }
      });
    },
  },
  mounted() {
    this.getName();
  },
};
</script>

<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
